﻿using Pb;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EginXTJ
{

    private static EginXTJ _instance;
    EginUser user = EginUser.Instance;
    public static EginXTJ Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new EginXTJ();
            }
            return _instance;
        }
    }    
    public int createrUid;
    public int roomId;
    public int totalRound;
    public int currentRound;
    public int roomStatus;
    public int roundType;
    public int roundId;
    public long systemCoin;//系统坐庄时庄家钱数
    //房间内所有玩家的数量
    public int playersNum;

    public int roundNum;//当前局数
    public int roundCardNum;//洗牌之前打的局数

    public long currentChip;
    public bool isBanker;
    //庄家信息
    public PaiPlayer bankerInfo;
    //是否放弃坐庄
    public int giveUpControl;
    //玩家信息
    public List<PaiPlayer> playersList;
    //房间内玩家的位置列表
    public List<int> seatList = new List<int>();
    //参与抢庄的玩家的id列表
    public List<int> grabMasterList = new List<int>();
    //发牌记录
    public List<PaiCard> cardHistory;

    public int bankerId;
    public bool isReconnect = false;
    //是否接收到准备通知了
    public bool isReady;

    public List<long> chipList;
    public int level;

    public List<int> shaiziNum;//存儲篩子點數
    public Dictionary<int, PaiInt64Array> poolChipsDic;//各个方位的总筹码
    public Dictionary<int, PaiInt64Array> ownChipsDic;//自己各个方位的总筹码
    public Dictionary<int, PaiCardGroup> paiCardsDic;//存储发牌信息
    public Dictionary<int, PaiInt64Array> coinMapDic;//存储玩家输赢信息；

    public PaiEnterRoundResponse newpb;

    /// <summary>
    /// 为房间中的玩家重新排序
    /// </summary>
    public void SortPlayer()
    {
        int index = 0;
        int DownSeat = 0;
        int RightSeat = 0;
        int UpSeat = 0;
        int LeftSeat = 0;
        for (int i = 0; i < playersList.Count; i++)
        {
            if (int.Parse(user.Uid) == playersList[i].Id)
            {
                index = i;
                break;
            }
        }

        if(index == 0){
            DownSeat = 0;
            RightSeat = 1;
            UpSeat = 2;
            LeftSeat = 3;
        }
        else if (index == 1)
        {
            DownSeat = 1;
            RightSeat = 2;
            UpSeat = 3;
            LeftSeat = 0;
        }
        else if (index == 2)
        {
            DownSeat = 2;
            RightSeat = 3;
            UpSeat = 0;
            LeftSeat = 1;
        }
        else if (index == 3)
        {
            DownSeat = 3;
            RightSeat = 0;
            UpSeat = 1;
            LeftSeat = 2;
        }
        seatList.Clear();
        seatList.Add(DownSeat);
        seatList.Add(RightSeat);
        seatList.Add(UpSeat);
        seatList.Add(LeftSeat);
    }


    public int ReturnPlayerSeat(int id)
    {
        int tempReture = 0;
        int index = 0;
        for (int i = 0; i < playersList.Count; i++)
        {
            if (id == playersList[i].Id)
            {
                index = i;
                break;
            }
        }

        for (int i = 0; i < seatList.Count; i++)
        {
            if (index == seatList[i])
            {
                tempReture = i;
                break;
            }
        }

        return tempReture;
    }
}
